package com.zw.a.basic.a13.demo08_priority;

//案例: 演示多线程的优先级问题.
/*
    Thread类中的成员方法:
        public final int getPriority();                 //获取当前线程的优先级.
        public final void setPriority(int priority)     //设置线程的优先级, 默认为5, 范围1-10
 */
public class Demo {
    public static void main(String[] args) {
        //1. 创建线程对象.
        MyThread mt1 = new MyThread("飞机");
        MyThread mt2 = new MyThread("高铁");
        MyThread mt3 = new MyThread("动车");

        //2. 设置线程的优先级
        mt2.setPriority(10);
        mt3.setPriority(1);

        //3. 开启线程.
        mt1.start();        //5
        mt2.start();        //10
        mt3.start();        //1

        //4. 打印线程的优先级及优先级的范围.
        //线程的优先级
        /*System.out.println(mt1.getPriority());
        System.out.println(mt2.getPriority());
        System.out.println(mt3.getPriority());
        System.out.println("--------------------");
        //优先级的范围.
        System.out.println(Thread.MAX_PRIORITY);        //最大优先级: 10
        System.out.println(Thread.NORM_PRIORITY);       //默认优先级: 5
        System.out.println(Thread.MIN_PRIORITY);        //最小优先级: 1*/
    }
}
